﻿
using Approval.Domain;
using Approval.Infrastructure.Interface;
using Approval.ReadAPI.Appliaction.Command.RLZRelationCommand;
using MediatR;
using Microsoft.AspNetCore.Mvc.RazorPages;
using PublicCommon;

namespace Approval.ReadAPI.Appliaction.CommandHandler.RLZRelationCommandHandler
{
    public class RLZRelationListCommandHandler : IRequestHandler<RLZRelationListCommand, List<RLZRelation>>
    {
        private readonly IRLZRelationRepository rLZRelationRepository;

        public RLZRelationListCommandHandler(IRLZRelationRepository rLZRelationRepository)
        {
            this.rLZRelationRepository = rLZRelationRepository;
        }

        public async Task<List<RLZRelation>> Handle(RLZRelationListCommand request, CancellationToken cancellationToken)
        {
            var res = await rLZRelationRepository.GetListInfo(x => x.RLZId.Equals(request.RLZId));
            var list = res.OrderByDescending(x => x.Id);
            return list.ToList();
        }
    }
}
